package com.ysd.modules.app.controller;

import com.ysd.common.utils.R;
import com.ysd.modules.app.entity.CourseEntity;
import com.ysd.modules.app.service.CoursesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author ky
 * @Date 2021/07/13
 * 课程控制
 */
@RestController
@RequestMapping("/app")
@Api(description = "APP课程接口")
public class AppCourseController {
    @Autowired
    private CoursesService coursesService;

    @GetMapping("getAllCourses")
    @ApiOperation("查询所有课程")
    public R getAllCourses() {
        List<CourseEntity> courseEntityList = coursesService.getAllCourses();
        return R.ok().put("courseEntityList", courseEntityList);
    }

    @PostMapping("getCourseById")
    @ApiOperation("根据id查询单个课程信息")
    public R getCourseById(int cid) {
        CourseEntity courseEntity = coursesService.getCourseById(cid);
        return R.ok().put("courseEntity", courseEntity);
    }
    
    @PostMapping("getCourseByStuId")
    @ApiOperation("根据id查询单个课程信息")
    public R getCourseByStuId(int stuId) {
        List<CourseEntity> cList = coursesService.getCourseByStudentId(stuId);
        return R.ok().put("courseEntity", cList);
    }
}
